#!/bin/bash
# 验证版本Centos7.x 版本
set -e

function init(){
echo init start 
sudo docker pull quay.io/prometheus/prometheus:v2.26.0
sudo docker pull grafana/grafana:9.2.20
sudo docker pull bitnami/kube-state-metrics:2.2.4
sudo docker pull quay.io/prometheus/alertmanager:v0.21.0
sudo docker pull timonwong/prometheus-webhook-dingtalk:v2.1.0
sudo docker pull bitnami/node-exporter:1.6.0


echo init start 
# 开始部署
deplopy
}

function init_victoriametrics() {
sudo mkdir -p /zpaas/vm/victoria-metrics-data
sudo chmod 777 /zpaas/vm/victoria-metrics-data
sudo docker pull victoriametrics/victoria-metrics:v1.76.1

}

function init_tick() {
sudo docker pull kapacitor:1.6
sudo docker pull chronograf:1.8.8
sudo docker pull influxtsdb/influxdb-admin:latest
sudo docker pull influxdb:1.8.0
}

function init_data() {
# alertmanager
sudo mkdir /alertmanager-resources
sudo chmod 777 /alertmanager-resources

# chronograf
sudo mkdir /chronograf-resources
sudo chmod 777 /chronograf-resources
}

function deplopy(){
echo deplopy start
# system env
cd system-env
sudo kubectl apply -f .

# exportes
cd ../exporters
sudo kubectl apply -f .

# rules
cd ../rules
sudo kubectl apply -f .

# alertmanager
cd ../alertmanager
sudo kubectl apply -f .

# kube-state-metrics
cd ../kube-state-metrics
sudo kubectl apply -f .

# grafana
cd ../grafana
sudo kubectl apply -f .

# influxdb
cd ../influxdb
sudo kubectl apply -f .

# kapacitor
cd ../kapacitor
sudo kubectl apply -f .

# prometheus
cd ../
sudo kubectl apply -f .
echo deplopy end 

check
}

function check(){
echo check
sudo kubectl -n monitoring get ds,pod,svc
}


init